package com.itheima.stock.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.stock.mapper.SysLogMapper;
import com.itheima.stock.pojo.entity.SysLog;
import com.itheima.stock.pojo.entity.SysUser;
import com.itheima.stock.service.LogService;
import com.itheima.stock.vo.req.LogsPageVo;
import com.itheima.stock.vo.resp.PageResult;
import com.itheima.stock.vo.resp.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {

    @Autowired
    private SysLogMapper sysLogMapper;

    @Override
    public R<PageResult<SysLog>> getLogsByPage(LogsPageVo logsPageVo) {
        //1.设置PageHelper分页参数
        PageHelper.startPage(logsPageVo.getPageNum(),logsPageVo.getPageSize());
        //2.调用mapper查询
        List<SysLog> logs = sysLogMapper.getLogsByParam(logsPageVo.getUsername(), logsPageVo.getOperation(), logsPageVo.getStartTime(), logsPageVo.getEndTime());
        //3.组装PageResult对象
        PageInfo<SysLog> pageInfo = new PageInfo<>(logs);
        PageResult<SysLog> pageResult = new PageResult(pageInfo);
        return R.ok(pageResult);
    }
}
